package y23.Oct;

import java.util.LinkedList;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = 0;
        int y = 1;
        int t = 0;
        while (n > y){
            y=x+y;
            x=y-x;
        }
        if(n==x||n==y){
            System.out.println(0);
        }else{
            int z = (n - x) < (y - n) ? n-x:y-n;
            System.out.println(z);
        }
    }
}
